import { defineStore } from 'pinia'
import { ref } from 'vue'

const useConsultStore = defineStore(
  'consult',
  () => {
    const illnessInfo = ref({
      illnessDesc: '', // 病情描述
      illnessTime: 1, // 患病时长
      consultFlag: 0, // 是否就诊过
      pictures: [], // 病情相关图片 [ { id, url } ]
    })

    const setIllnessInfo = (data) => {
      Object.assign(illnessInfo.value, data)
    }

    // 就诊类型
    const type = ref(1) // 1找医生 2极速问诊 3开药问诊
    const setType = (newType) => (type.value = newType)

    // 极速问诊类型
    const illnessType = ref(0) // 0普通1三甲
    const setIllnessType = (newIllnessType) =>
      (illnessType.value = newIllnessType)

    // 科室id
    const depId = ref('') // 科室id
    const setDepId = (newDepId) => (depId.value = newDepId)

    // 患者id
    const patientId = ref('')
    const setPatientId = (newPatientId) => (patientId.value = newPatientId)

    const clear = () => {
      clearIllnessInfo()
      type.value = 1
      illnessType.value = 0
      depId.value = ''
      patientId.value = ''
    }

    const clearIllnessInfo = () => {
      illnessInfo.value = {
        illnessDesc: '', // 病情描述
        illnessTime: 1, // 患病时长
        consultFlag: 0, // 是否就诊过
        pictures: [], // 病情相关图片 [ { id, url } ]
      }
    }

    const payUrl = ref('')

    return {
      payUrl,
      illnessInfo,
      setIllnessInfo,
      type,
      setType,
      illnessType,
      setIllnessType,
      depId,
      setDepId,
      patientId,
      setPatientId,
      clear,
      clearIllnessInfo,
    }
  },
  {
    persist: true,
    // persist: {
    //   paths: ['illnessInfo'],
    // },
  }
)

export default useConsultStore
